<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2024/2/22
 * Time: 10:24
 */

namespace app\api\model;

class Banner extends Base
{
    protected $hidden = ['banner_sort', 'banner_time', 'banner_update_time', 'banner_status'];
    /**
     * 多条查询
     * @param $where
     * @param $field
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectData(){
        return self::where('banner_status', 1)->order('banner_sort desc')->limit(5)->select();
    }

    /**
     * 读取器，获取完整图片绝对路径
     * @param $url  图片地址
     * @param $data 表中所有数据组成的数组，框架根据当前模型自动获取
     * @return string
     */
    public function getBannerImageAttr($url, $data)
    {
        if($data['banner_image']){
            return $this->prefixImgUrl($url);
        }else{
            return '';
        }

    }
}